﻿using System.Text.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EpubFactory.Common
{
    public static class JsonHelper
    {
        public static string Serialize(object obj)
        {
            return JsonSerializer.Serialize(obj);
        }

        public static T Deserialize<T>(string input)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                return default(T);
            }
            try
            {
                return JsonSerializer.Deserialize<T>(input);
            }
            catch (JsonException ex)
            {
                throw new InvalidCastException("解析异常");
            }
        }
        
    }
}
